
rm(list=ls())

library(foreign)
library(ggplot2)
library(gridExtra)
library(grid)
library(lattice)
library(ggrepel)

################# 2018 Effects
setwd("")

diffdiffall<-read.dta("Transformative_voting_scales.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.8)  

color.names<-c("black", "grey55")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(outcome, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(bandwidth), size=effective_N)) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(bandwidth)), width=0, size=2) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(bandwidth)), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="", fill = "Bandwidth") +
  theme(text = element_text(size=30)) +
  scale_y_continuous(limits=c(-0.5, 1.5)) + 
  coord_flip() + theme(legend.position="bottom") +
  scale_size(range = c(7, 15)) +
  scale_colour_manual(values=color.names) +  theme(legend.title = element_blank()) +
  geom_label_repel(aes(label=label_all), size=6, position = pd, fill="white", min.segment.length = 0, force=120, alpha=0.8)


plot1
ggsave(plot1, file="transformative_effects_2018.png", width=10, height=6, scale=2)


################# Heterogeneities [2018]

#### Optimal BW
setwd("")

diffdiffall<-read.dta("Transformative_voting_hets.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.57)  

color.names<-c("black", "grey55")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(outcome, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(SESHet), size=effective_N), position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(SESHet)), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(SESHet)), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="", fill = "Bandwidth") +
  theme(text = element_text(size=30)) +
  scale_y_continuous(limits=c(-0.5, 1.7)) + 
  coord_flip() + theme(legend.position="bottom") +
  scale_size(range = c(7, 15)) +
  scale_colour_manual(values=color.names) +  theme(legend.title = element_blank()) 


plot1
ggsave(plot1, file="transformative_effects_hets.png", width=10, height=6, scale=2)



#### Full BW
setwd("")

diffdiffall<-read.dta("Transformative_voting_hets_full_bw.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.57)  

color.names<-c("black", "grey55")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(outcome, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(SESHet), size=effective_N), position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(SESHet)), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(SESHet)), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="", fill = "Bandwidth") +
  theme(text = element_text(size=30)) +
  scale_y_continuous(limits=c(-0.5, 1.7)) + 
  coord_flip() + theme(legend.position="bottom") +
  scale_size(range = c(7, 15)) +
  scale_colour_manual(values=color.names) +  theme(legend.title = element_blank()) 


plot1
ggsave(plot1, file="transformative_effects_hets_full_bw.png", width=10, height=6, scale=2)



################# Other Heterogeneities [2018]
setwd("")

diffdiffall<-read.dta("Transformative_voting_hets_other.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.9)  

color.names<-c("grey55", "black")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(outcome, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(condition), size=effective_N), position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(condition)), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(condition)), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  facet_wrap(~moderator) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="", fill = "Bandwidth") +
  theme(text = element_text(size=30)) +
  scale_y_continuous(limits=c(-1, 1)) +  theme(legend.position="bottom") +
  scale_size(range = c(7, 15)) +  theme(legend.title = element_blank()) + coord_flip() +
  scale_colour_manual(values=color.names) 


plot1
ggsave(plot1, file="transformative_effects_hets_other.png", width=12, height=8, scale=2)


################# IV Estimates [2018]
setwd("")

diffdiffall<-read.dta("IV_estimates.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.57)  

color.names<-c("black", "grey55")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(outcome, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(bandwidth), size=effective_N), position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(bandwidth)), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(bandwidth)), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="", fill = "Bandwidth") +
  theme(text = element_text(size=24)) +
  scale_y_continuous(limits=c(-1, 1)) + 
  coord_flip() + theme(legend.position="bottom") +
  scale_size(range = c(7, 15)) +
  scale_colour_manual(values=color.names) +  theme(legend.title = element_blank()) 


plot1
ggsave(plot1, file="IV_effects_2016.png", width=7, height=4, scale=2)
 
################# 2016 Effects

setwd("")

diffdiffall<-read.dta("Transformative_voting_2016.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.57)  

color.names<-c("black", "grey55")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(outcome, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(bandwidth), size=effective_N)) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(bandwidth)), width=0, size=2) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(bandwidth)), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="", fill = "Bandwidth") +
  theme(text = element_text(size=24)) +
  scale_y_continuous(limits=c(-0.5, 0.5)) + 
  coord_flip() + theme(legend.position="bottom") +
  scale_size(range = c(7, 15)) +
  scale_colour_manual(values=color.names) +  theme(legend.title = element_blank()) +
  geom_label_repel(aes(label=label_all), size=6, position = pd, fill="white", min.segment.length = 0, force=120, alpha=0.8)


plot1
ggsave(plot1, file="transformative_effects_2016.png", width=7, height=4, scale=2)


################# Pooled Effects
setwd("")

diffdiffall<-read.dta("Transformative_voting_both_years.dta")
attach(diffdiffall) 

color.names<-c("black", "grey55")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(outcome, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(bandwidth), size=effective_N), position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(bandwidth)), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(bandwidth)), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="") +
  theme(text = element_text(size=20)) +
  scale_y_continuous(limits=c(-0.5, 0.5)) + 
  coord_flip() + theme(legend.position="bottom")  +
  scale_size(range = c(7, 15)) +
  scale_colour_manual(values=color.names) +  theme(legend.title = element_blank()) +
  geom_label_repel(aes(label=label_all), size=4, position = pd, fill="white", min.segment.length = 0, force=120, alpha=0.8)



plot1
ggsave(plot1, file="transformative_effects_pooled.png", width=5, height=3, scale=2)



######### Covariate Balance

setwd("")

diffdiffall<-read.dta("covariate_balance.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.57)  

color.names<-c("black", "grey55")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=outcome))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour = factor(bandwidth), size=effective_N), position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour = factor(bandwidth)), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour = factor(bandwidth)), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Civic Outcomes (Standardized)", title="", fill = "Bandwidth") +
  theme(text = element_text(size=30)) +
  scale_y_continuous(limits=c(-1, 1)) + 
  coord_flip() + theme(legend.position="bottom") +
  scale_size(range = c(7, 15)) +
  scale_colour_manual(values=color.names) +  theme(legend.title = element_blank()) 


plot1
ggsave(plot1, file="covariate_balance.png", width=8, height=12, scale=2)

